from bookmarks.models import Landmark, Tag, LandmarkTag, GeoField
from django.contrib import admin
from googlemapwidget import GoogleMapWidget
from reversion.admin import VersionAdmin
import sys
from pprint import pformat

class LandmarkTagInline(admin.TabularInline):
    model = LandmarkTag
    extra = 2
    verbose_name = 'Tag'
    verbose_name_plural = 'Tags'

class TagLandmarkInline(admin.TabularInline):
    model = LandmarkTag
    extra = 0
    verbose_name = 'Landmark'
    verbose_name_plural = 'Landmarks'

class LandmarkAdmin(VersionAdmin):
    list_display = ('name', 'slug', 'target_url')
    extra = 0
    prepopulated_fields = {"slug": ("name",)}
    search_fields = ('name', 'content')
    inlines = (LandmarkTagInline,)
    fieldsets = (
        (None, {
            'fields': ('name','slug','content', 'target_url', 'image', 'location'),
        }),
    )
    formfield_overrides = {
        GeoField: { 'widget' : GoogleMapWidget(attrs={ 'geolocate' : 'false'}) },
    }

class TagAdmin(VersionAdmin):
    list_display = ('name', 'tag_type')
    search_fields = ('name', 'content')
    inlines = (TagLandmarkInline,)
    prepopulated_fields = {"slug": ("name",)}

class LandmarkTagAdmin(VersionAdmin):
    list_display = ('landmark', 'tag', 'priority')

admin.site.register(LandmarkTag, LandmarkTagAdmin)
admin.site.register(Tag, TagAdmin)
admin.site.register(Landmark, LandmarkAdmin)
